﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using NHibernate;
using NHibernate.Cfg;
using System.Collections;




namespace ThorMVR
{
    public partial class fLogin : Form
    {
        public fLogin()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
            this.MaximizeBox = false;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            btn_logar.Enabled = false;
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void btn_cancelar_Click(object sender, EventArgs e)
        {
            fLogin.ActiveForm.Close();
   
        }

        private void btn_logar_Click(object sender, EventArgs e)
        {


       



        }

        private void txt_codigo_(object sender, EventArgs e)
        {

        }

        private void txt_codigo_TextChanged(object sender, EventArgs e)
        {
            int userid;

            Boolean b = Int32.TryParse(txt_codigo.Text, out userid);
            if(b)
            {
                ISession session = ClassModels.NHibernateHelper.GetCurrentSession();

                IQuery query = session.CreateQuery("FROM SistemaUsuarios WHERE IdUsuario=:id");

                query.SetString("id", userid.ToString());

                IList<ClassModels.SistemaUsuarios> acc = query.List<ClassModels.SistemaUsuarios>();

                session.Close();

                if (acc.Count != 0)
                {
                    l_NomeUsuario.Text = acc[0].NomeCompleto;

                    l_NomeUsuario.Visible = true;

                    btn_logar.Enabled = true;

                }
                else
                {
                    l_NomeUsuario.Text = "Usuario não cadastrado";

                    l_NomeUsuario.Visible = true;

                    btn_logar.Enabled = false;
                }



            }else
            {
                if (txt_codigo.Text != "")
                {
                    MessageBox.Show("Somente são aceitos números!", "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txt_codigo.Clear();
                    btn_logar.Enabled = false;
                    l_NomeUsuario.Text = "";
                }
            }



            


        }


    }
}
